package com.isprint.jslx.lcc.Jfinal;

import com.isprint.jslx.config.CommonJfinalConfig;
import com.isprint.jslx.lcc.model._MappingKit;
import com.isprint.jslx.lcc.mysq.MysqlProperties;
import com.isprint.jslx.lcc.redis.RedisProperties;
import com.isprint.jslx.lcc.wechat.model._MappingKitWechat;
import com.jfinal.config.Constants;
import com.jfinal.config.Plugins;
import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.CaseInsensitiveContainerFactory;
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.render.ViewType;

/**
 * Created by ydw on 2017/7/14.
 */
public class LccJfinalConfig extends CommonJfinalConfig {
   public static Prop lcc = PropKit.use("config/lcc.properties");
    /**
     * 当前是否为开发模式
     */
    public static String GLOBALUSERUUID = "GLOBAL_USER_UUID";

    public static boolean IS_DEV=lcc.getBoolean("is_dev",true);

    public static boolean DEV_MODE=lcc.getBoolean("dev_mode",true);

    public static boolean SHOW_SQL=lcc.getBoolean("show_sql",true);

    public static boolean MERGE_SQL=lcc.getBoolean("merge_sql",true);

    public static int PAGE_SIZE=lcc.getInt("page_size",20);






    public void configConstant(Constants constants) {
        constants.setMaxPostSize(100*1024*1024);
        constants.setDevMode(DEV_MODE);
        constants.setViewType(ViewType.FREE_MARKER);

    }

    public void configPlugin(Plugins plugins) {
        super.configPlugin(plugins);
        System.out.println("config plugin");
//        添加redis插件
        plugins.add(RedisProperties.getRedisPlugin());
        System.out.println("--redisPlugin is added");
//        添加链接池
        DruidPlugin druidPlugin = MysqlProperties.getdruidPlugin();
//        StatFilter stat = new StatFilter();
//        stat.setMergeSql(MERGE_SQL);// 设置是否合并sql
//        druidPlugin.addFilter(stat);
        plugins.add(druidPlugin);
        System.out.println("--mysql链接池 is added");

//        ActiveRecordPlugin
        ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
        arp.setShowSql(SHOW_SQL);// 配置Mysql方言
        arp.setDialect(new MysqlDialect());
        arp.setContainerFactory(new CaseInsensitiveContainerFactory());// 配置属性名(字段名)大小写不敏感容器工厂
        plugins.add(arp);
        System.out.println("ActiveRecordPlugin is added");
//        自动完成表与实体类的映射
        _MappingKit.mapping(arp);
        //添加微信的映射
        _MappingKitWechat.mapping(arp);
    }
}
